home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992…ugust: Hack to the Future / ADC Developer CD (1992-08) (''Hack To The Future'')_iso / Dev.CD 199208.iso / Periodicals / develop / develop 9 code / Tracks / Tracks ƒ / ShowINIT.a < prev    next >
Encoding:
Text File  |  1992-01-06  |  14.6 KB  |  521 lines  |  [TEXT/MPS ]

  1. ; File: ShowINIT.a
  2. ; Last Modified: Friday, Jan 15, 1991
  3. ;------------------------------------------------------------------------------------------------
  4. ;
  5. ;    INIT notification routine
  6. ;     by Paul Mercer, Darin Adler, and Paul Snively from an idea by Steve Capps
  7. ;        icl4/icl8 support by Brad Lowe
  8. ;
  9. ;    Created:  6/7/87  PM    - First version.
  10. ;    Modified: 6/15/87 PM    - Changed to standard (Pascal) calling conventions.
  11. ;          6/20/87 PM    - Fixed color & Finder bug on Mac II.
  12. ;          6/22/87 DBA    - Improved handling of QuickDraw.
  13. ;          6/29/87 DBA    - Used scratch8 to avoid conflict with “Easy Access”.
  14. ;          6/30/87 DBA    - Changed to a 4-byte scheme with “checksum”.
  15. ;          6/30/87 PFS    - Separated into ShowINIT and InnerShowINIT.
  16. ;          7/1/87  DBA    - Fixed stack bug and switched to CurApName+.
  17. ;          7/2/87  PM    - Added check for old signature in ApplScratch for
  18. ;                   backword compatibility (TMON Startup).
  19. ;          7/3/87  PM    - Removed _SysBeep in ErrorExit since it causes a crash.
  20. ;                   Also changed ICN# plotter to srcOr mode for Blinker.
  21. ;          7/13/87 PM    - Fixed a3 trashing bug in InnerShowINIT - exit code left
  22. ;                   word on stack (reported by D. Dunham). 
  23. ;          7/21/87 PM    - Due to popular demand, InitGraf is no longer being called.
  24. ;                   This avoids the gamma correction problem with Startupscreens
  25. ;                   getting  “washed out” by ShowINIT though someone else is still
  26. ;                   bound to call InitGraf sooner or later (i.e. InitWindows).
  27. ;          7/29/87 PM    - Put InitGraf back in; this is required (reported by C. Derossi
  28. ;                   at Apple Tech Support).  Took out GetPort/SetPort.
  29. ;        10/06/87  PM    - Set CurrentA5 properly.  Rearranged myVars.
  30. ;        12/28/87  PM    - Major revision to accomodate future INIT31 based ShowINIT.
  31. ;        07/14/88  PM    - Major revision to get rid of above 'accomodations'.
  32. ;                   Added color icon 'cicn' support and fixed beep crash.
  33. ;                   Removed support for old signature.
  34. ;        1/21/91      BL    - Added support for icl4's and icl8's.  Removed support for
  35. ;                       for cicn's.  An ICN# must be included for each color icl you want
  36. ;                    displayed (to draw the mask, and for when there is no color or less
  37. ;                    than 4 bit color.)  Showinit displays either an icl4, icl8, or a black
  38. ;                    and white ICN#, depending on what resources are present, and the color
  39. ;                    depth available.
  40. ;
  41. ;------------------------------------------------------------------------------------------------
  42.  
  43.         INCLUDE    'Traps.a'
  44.         INCLUDE    'QuickEqu.a'
  45.         INCLUDE    'SysEqu.a'
  46.         INCLUDE    'ToolEqu.a'
  47.  
  48.         BLANKS  ON
  49.         STRING  ASIS
  50.  
  51. True        equ    1
  52. False        equ    0
  53.  
  54. Debug        equ    True
  55. ;Debug        equ    False
  56.  
  57. myH            equ    CurApName+32-4        ; a GREAT place to store 4 bytes (it was Darin's idea)
  58. myCheck        equ    myH+2            ; a simple checksum of myH to determine first-timeness
  59. firstX        equ    8            ; X coordinate of first icon to be drawn
  60. bottomEdge    equ    8+32            ; this far from bottom of screen
  61. iconWidth    equ    32            ; size of icon (square normally)
  62. defaultMoveX    equ    40            ; default amount to move icons
  63. checksumConst    equ    $1021            ; constant used for computing checksum
  64. minColorDepth    equ    4            ; minimum bits/pixel for drawing color icons
  65.  
  66. maskOffset    equ    128            ; offset to mask in ICN#
  67. iconRowBytes    equ    32/8            ; 32/8 bits
  68.  
  69. hasCQDBit        equ    6            ; this bit in ROM85 is cleared if Color QuickDraw is available
  70.  
  71. iconID            equ    6+4            ; positive stackframe objects
  72. showINITArgs    equ    4
  73.  
  74.  
  75. ; INITDraw1Bit arguments
  76. moveX            equ    4+4        ; a short
  77. iconPtrHdl        equ    6+4        ; a long
  78. theIconID        equ 10+4    ; added
  79. initDrawArgs    equ    10        ; was 6
  80.  
  81. myVars        RECORD    0,DECREMENT
  82. saveA5        ds.l    1
  83. localA5        ds.l    1
  84. thePort        ds.l    1            ; my own QuickDraw (required!)
  85.         ds.b    grafSize-4        ;  other QuickDraw globals (except thePort)
  86.  
  87. destRect    ds.w    4
  88. myBitMap    ds.b    bitMapRec
  89. myPort        ds.b    portRec
  90. icl4Hand    ds.l    1
  91. icl8Hand    ds.l    1
  92.  
  93. varsSize    equ    *
  94.         ENDR
  95.  
  96. ;    DrawIcls routine...
  97. iclVars        RECORD    0,DECREMENT
  98. pixMap    ds.b    pmRec
  99. GDHand    ds.l    1
  100. iclVarSize equ    *
  101.         ENDR
  102.         
  103. ; iclDraw arguments
  104. pixSize            equ    4+4        ; either 4, 8, (or higher)
  105. DestPM            equ    6+4        ; the dest rect pointer
  106. destRect        equ 10+4    ; dest pixmap (ptr) for copybits
  107. iclHand            equ    14+4    ; handle of icl...  assumed to be good
  108. iclDrawArgs        equ    14        ; 
  109.  
  110. ;------------------------------------------------------------------------------------------------
  111. ;                                
  112. ;    Displays the ICN# (cicn when in 4 bit mode or higher) specified by iconID and
  113. ;     move the pen horizontally by moveX.
  114. ;    Pass a -1 in moveX to move the standard amount, moveX should be 40 for most ICN#'s
  115. ;
  116. ;    PROCEDURE ShowINIT(iconID: Integer; moveX: Integer); EXTERNAL
  117. ;
  118. ;    pascal void ShowINIT(iconID, moveX)
  119. ;        short iconID, moveX;
  120. ;        extern;
  121. ;
  122. ;------------------------------------------------------------------------------------------------
  123. ShowINIT:    PROC    EXPORT
  124.         IMPORT    INITDraw1Bit
  125.         link    a6,#0            ; create stack frame
  126.         movem.l    d3-d7/a2-a4,-(sp)    ; save standard registers
  127.         
  128.  
  129. ShowINIT1Bit
  130.  
  131.         clr.l    -(sp)            ; try to get the ICN# resource
  132.         move.l    #'ICN#',-(sp)
  133.         move.w    iconID(a6),-(sp)
  134.         _GetResource
  135.         move.l    (sp)+,A0
  136.         
  137.         Move.l    A0, D0
  138.         
  139.         beq.s    ShowINITError        ; can't get it, give up
  140.  
  141.         _HLock                ; Lock the ICN# resource in A0
  142.         Move.l    A0, D0
  143.         
  144.         move.l    d0,-(sp)        ; leave handle on the stack for ReleaseResource
  145.         move.l    d0,a0
  146.         move.l    (a0),a0            ; dereference
  147.  
  148.         move.w    iconID(a6), -(sp)    ; the icon id, for icl4, icl8 -- BL
  149.         move.l    a0,-(sp)        ; icon pointer (iconPtrHdl)
  150.         move.w    moveX(a6),-(sp)        ; moveX    (MoveX)
  151.         
  152.         bsr    INITDraw1Bit        ; draw
  153.         _ReleaseResource        ; releaese the resource
  154.  
  155. ShowINITExit:
  156.  
  157.         movem.l    (sp)+, d3-d7/a2-a4    ; restore registers
  158.         unlk    a6            ; ditch stack frame
  159.         move.l    (sp)+, a0        ; get return address
  160.         addq.l    #showINITArgs, sp    ; ditch incoming arguments
  161.         jmp    (a0)            ; return to caller
  162.  
  163. ShowINITError:
  164.         IF    Debug THEN
  165.         move.w    #1,-(sp)        ; just beep
  166.         _SysBeep
  167.         ENDIF
  168.         bra.s    ShowINITExit
  169.  
  170. ShowINITCredits:
  171.         dc.w    'ShowINIT by Paul Mercer'
  172.         dc.w    'modified 1/22/91 to show'
  173.         dc.w    'icl4 and icl8 types'
  174.         ENDPROC
  175.  
  176.  
  177. ;------------------------------------------------------------------------------------------------
  178. ;
  179. ;    Initializes the world and sets up the drawing rectangle
  180. ;
  181. ;------------------------------------------------------------------------------------------------
  182. INITInit:    PROC    EXPORT
  183.         WITH    myVars
  184.  
  185.         move.l    CurrentA5,saveA5(a6)    ; PM 10/6 save host A5
  186.         lea    localA5(a6),a5        ; PM7/21
  187.         move.l    a5,CurrentA5
  188.         pea    thePort(a6)        ; PM 10/6 use a5 reference instead of a6
  189.         _InitGraf            ; fixes color bug as per DA@ICOM
  190.         pea    myPort(a6)
  191.         _OpenPort
  192.  
  193.         move.w    myH,d0            ; get my h var
  194.         rol.w    #1,d0            ; compare against checksum
  195.         eor.w    #checksumConst,d0
  196.         cmp.w    myCheck,d0
  197.         beq.s    ScratchOK        ; checks, so go on
  198.         move    #firstX,myH        ; else initialize as first time
  199. ScratchOK:
  200.         lea    myPort(a6),a0        ; compute the destination rectangle
  201.         move.w    portBounds+bottom(a0),d0
  202.         sub.w    #bottomEdge,d0
  203.         swap    d0
  204.         move.w    myH,d0
  205.  
  206.         move.l    d0,destRect(a6)
  207.         move.l    d0,destRect+botRight(a6)
  208.         add.w    #iconWidth,destRect+right(a6)
  209.         add.w    #iconWidth,destRect+bottom(a6)
  210.  
  211.         rts
  212.  
  213.         ENDWITH
  214.         ENDPROC
  215.  
  216.  
  217. ;------------------------------------------------------------------------------------------------
  218. ;
  219. ;    Cleans up the work done by INITInit and advances the icon drawing position
  220. ;
  221. ;------------------------------------------------------------------------------------------------
  222. INITCleanup:    PROC    EXPORT
  223.         WITH    myVars
  224.  
  225.         move.w    myH,d0                ; get current position
  226.         move.w    moveX(a6),d1        ; get delta x
  227.         bpl.s    NotDefault            ; not default (-1)
  228.         move.w    #defaultMoveX,d1    ; default
  229. NotDefault:
  230.         add.w    d1,d0            ; increment icon position
  231.         move.w    d0,myH            ;  and save in ‘global’
  232.         rol.w    #1,d0            ; recompute checksum
  233.         eor.w    #checksumConst,d0
  234.         move.w    d0,myCheck        ;  and save it
  235. Exit:
  236.         pea    myPort(a6)
  237.         _ClosePort
  238.         ; *** (DBA) I think that QuickDraw leaves handles around.
  239.         ; *** (DBA) Too bad we can't get rid of them...
  240.         move.l    saveA5(a6),a5        ; PM 10/6 restore host A5
  241.         move.l    a5,CurrentA5
  242.         rts
  243.  
  244.         ENDWITH
  245.         ENDPROC
  246.  
  247.  
  248. ;------------------------------------------------------------------------------------------------
  249. ;                                
  250. ;    display the ICN# pointed to by iconPtr and move the pen horizontally by moveX
  251. ;     pass a -1 in moveX to move the standard amount, moveX should be 40 for most ICN#'s
  252. ;
  253. ;    PROCEDURE INITDraw1Bit(iconPtr: ICONListPtr; moveX: Integer); EXTERNAL
  254. ;
  255. ;    pascal void INITDraw1Bit(iconPtr, moveX)
  256. ;        ICONList *iconPtr;
  257. ;        short moveX;
  258. ;        extern;
  259. ;
  260. ;------------------------------------------------------------------------------------------------
  261. INITDraw1Bit:    PROC    EXPORT
  262.         IMPORT    INITInit, INITCleanup:CODE
  263.         IMPORT     DrawIcls    ;    plots icl4 or icl8..
  264.         
  265.         WITH    myVars
  266.  
  267.         link    a6,#varsSize        ; create stack frame
  268.         movem.l    d3-d7/a2-a4,-(sp)    ; save standard registers
  269.         bsr    INITInit                ; initialize for drawing
  270.         
  271.         clr.l    icl4Hand(a6)        ; 
  272.         clr.l    icl8Hand(a6)
  273.         
  274.         btst.b    #hasCQDBit,ROM85    ; try to get a color icon if CQD exists
  275.         bne.s    DrawMask            ; I could use SysEnvirons but I don't want to
  276.         
  277. ;    ////  Try and load an icl4 and icl8
  278. ; Get the resources here so there won't be a delay after drawing the mask...  
  279. ; Get both- their small, and just use what we need and toss anything not nil back later...
  280.  
  281.         clr.l    -(sp)            ; try to get an icl4 resource
  282.         move.l    #'icl4',-(sp)
  283.         move.w    theIconID(a6),-(sp)
  284.         _GetResource
  285.         move.l    (sp)+, icl4Hand(A6);
  286.         
  287.         clr.l    -(sp)            ; try to get icl8 resource
  288.         move.l    #'icl8', -(sp)
  289.         move.w    theIconID(a6),-(sp)
  290.         _GetResource
  291.         move.l    (sp)+,icl8Hand(A6);
  292.                 
  293. DrawMask:
  294.  
  295.         move.l    iconPtrHdl(a6),a3    ; get ICN# pointer
  296.         lea    myBitMap(a6),a4        ; point to bitmap structure
  297.         move.l    a3,baseAddr(a4)        ; fill it out
  298.         add.l    #maskOffset,baseAddr(a4) ; skip to mask
  299.         move    #iconRowBytes,rowBytes(a4)
  300.         move.l    #0,bounds(a4)        ; 0,0 topleft
  301.         move.w    #iconWidth,bounds+bottom(a4) ; 32,32 botright
  302.         move.w    #iconWidth,bounds+right(a4)
  303.  
  304.         move.l    a4,-(sp)        ; punch hole with mask
  305.         lea    myPort(a6),a2        ; get the desk port
  306.         pea    portBits(a2)        ;  for its portbits
  307.         pea    srcRect
  308.         pea    destRect(a6)
  309.         move    #srcBic,-(sp)        ; punch a hole
  310.         clr.l    -(sp)            ; no clip region
  311.         _CopyBits
  312.  
  313.         btst.b    #hasCQDBit,ROM85    ; try to get a color icon if CQD exists
  314.         bne    DrawBW        ;
  315.  
  316.     ; Get depth of main screen...
  317.         move.l    MainDevice,a3        ; get handle to main device
  318.         move.l    (a3),a3                ; dereference
  319.         move.l    gdPMap(a3),a3        ; get its pixmap handle
  320.         move.l    (a3),a3                ; dereference it
  321.  
  322.         cmp.w    #minColorDepth, pmPixelSize(a3);    Pixel depth less than 4?
  323.         blt        DrawBW
  324.         
  325.         cmp.w    #8, pmPixelSize(a3);    Use routine for 8 bit and higher screens
  326.         bge.s    Handle8Bit
  327.         
  328.         ; This is Handle4Bit    (must be 4 bit)
  329.         
  330.         cmp.l     #0, icl4Hand(a6)
  331.         beq.s    try8
  332.         ; draw a icl4 in 4 bit mode, this is the best combination
  333.         
  334. ;        ------- 
  335.         move.l    icl4Hand(a6), -(sp)     ; the icl handle
  336.         pea        destRect(a6)
  337.         pea        portBits(a2)    ; for copybits...
  338.         move.w    #4, -(sp)    ; depth of main screen
  339.         bsr        DrawIcls;
  340. ;        -------
  341.         
  342.         bra.s        DoneDrawing
  343.         
  344. try8:    cmp.l    #0, icl8Hand(a6)
  345.         beq.s    DrawBW
  346.         ; draw a icl8 in 4 bit mode
  347. ;        -------
  348.         move.l    icl8Hand(a6), -(sp)     ; the icl handle
  349.         pea        destRect(a6)
  350.         pea        portBits(a2)    ; for copybits...
  351.         move.w    #8, -(sp)    ; depth of main screen
  352.         bsr        DrawIcls;
  353. ;        -------
  354.         bra.s    DoneDrawing
  355.         
  356. Handle8Bit:                            ; Handle 8 bit (and higher) screens..
  357.         cmp.l     #0, icl8Hand(a6)
  358.         beq.s    try4
  359.         ; draw a icl8 in 8 bit mode
  360. ;        -------
  361.         move.l    icl8Hand(a6), -(sp)     ; the icl handle
  362.         pea        destRect(a6)
  363.         pea        portBits(a2)    ; for copybits...
  364.         move.w    #8, -(sp)        ; depth of icl 
  365.         bsr        DrawIcls;
  366. ;        -------
  367.         bra.s    DoneDrawing
  368.         
  369. try4:    cmp.l    #0, icl4Hand(a6) ;        Couldnt find an icl8, is there an icl4?
  370.         beq.s    DrawBW
  371.         ; draw a icl4 in 8 bit mode
  372. ;        -------
  373.         move.l    icl4Hand(a6), -(sp)     ; the icl handle
  374.         pea        destRect(a6)
  375.         pea        portBits(a2)    ; for copybits...
  376.         move.w    #4, -(sp)    ; depth of main screen
  377.         bsr        DrawIcls;
  378. ;        -------
  379.         bra.s    DoneDrawing
  380.  
  381. DrawBW:    ; Draw the ICN# black and white pattern... 
  382.  
  383.         sub.l    #128,baseAddr(a4)
  384.         move.l    a4,-(sp)        ; now draw (or) icon
  385.         pea    portBits(a2)
  386.         pea    srcRect
  387.         pea    destRect(a6)
  388.         move    #srcOr,-(sp)
  389.         clr.l    -(sp)
  390.         _CopyBits
  391.  
  392. DoneDrawing:    ; Dispose of any icl4/icl8 handles... 
  393.         cmp.l    #0, icl4Hand(a6)
  394.         beq.s    release2
  395.         move.l    icl4Hand(a6), -(sp)
  396.         _ReleaseResource
  397. release2:
  398.         cmp.l    #0, icl8Hand(a6)
  399.         beq.s    OuttaHere
  400.         move.l    icl8Hand(a6), -(sp)
  401.         _ReleaseResource
  402.  
  403. OuttaHere:
  404.         bsr    INITCleanup                ; cleanup, advance icon location
  405.         movem.l    (sp)+,d3-d7/a2-a4    ; restore registers
  406.         unlk    a6                    ; ditch stack frame
  407.         move.l    (sp)+,a0            ; get return address
  408.         
  409.         add.l    #initDrawArgs, sp    ; ditch incoming args
  410.         
  411.         jmp    (a0)                    ; back to caller
  412.  
  413. srcRect:    dc.w    0,0,32,32        ; for copybits
  414.  
  415.         ENDWITH
  416.         ENDPROC
  417.  
  418.  
  419.  
  420.  
  421. ;------------------------------------------------------------------------------------------------
  422. ;
  423. ;    Draws an icl4 or icl8, depending on the size.  Assumes a valid handle is passed.
  424. ;    void DrawIcls(Handle iclHand, Rect *destRect, PixMap *DestPM, word pixSize);
  425. ;
  426. ;    Local varibles:
  427. ;        Handle : GDHand;
  428. ;        PixMap:    pixMap;
  429. ;
  430. ;------------------------------------------------------------------------------------------------
  431.  
  432. DrawIcls:    PROC    EXPORT
  433.         WITH    iclVars
  434.         
  435.         
  436.         link    a6,#iclVarSize        ; create stack frame
  437.         movem.l    d7/a1-a4,-(sp)        ; save standard registers
  438.         
  439.     ;    _Debugger ;
  440.         
  441.         move.w    pixSize(a6), d7        ; pixSize into d7
  442.         move.l    iclHand(a6), a4        ; the resource of type icl4 or icl8
  443.         move.l    DestPM(a6),  a2        ; take out?
  444.         lea        pixMap(a6), a3        ; local PixMap to a3
  445.  
  446.         lea        destRect(a6), a1
  447.         move.l    destRect(a6), a1
  448.         
  449.         subq.l    #4, sp
  450.         Move.w    d7,    -(sp)
  451.         _GetCTable                    ; Get system clut..
  452.         Move.l    (a7)+, pmTable(a3)
  453.  
  454.         beq        Failed                ; Couldn't get it...  unusual
  455.         
  456.         subq.l    #4, sp                ; Get their graphic device handle
  457.         _GetGDevice
  458.         Move.l    (sp)+, GDHand(a6)
  459.         
  460.         move.l    A4, A0        ; lock the icl4/8 handle
  461.         _Hlock
  462.         Move.l    (a4), pmBaseAddr(a3)    ; derefrence icl handle
  463.         
  464.         ext.l    d7        ; multiply size * 4
  465.         move.l    d7, d0
  466.         asl.l    #2, d0    ; mult by 4 for rowbytes
  467.         ori.w    #$8000, d0        ; denotes a pixmap 
  468.         move.w    d0, pmRowBytes(a3); insert into structure
  469.         
  470.         clr.w    pmVersion(a3)
  471.         clr.w    pmPackType(a3)
  472.         clr.l    pmPackSize(a3)
  473.         
  474.         movea.l    GDHand(a6), a0        ; Get HRes and VRes
  475.         movea.l    (a0), a0    ; derefrence GDHandle
  476.         movea.l    gdPMap(a0), a0
  477.         movea.l    (a0), a0
  478.         move.l    pmHRes(a0), pmHRes(a3)
  479.         move.l    pmVRes(a0), pmVRes(a3)
  480.         
  481.         clr.w    pmPixelType(a3)
  482.         move.w    d7, pmPixelSize(a3)
  483.         move.w     #1, pmCmpCount(a3)
  484.         move.w    d7, pmCmpSize(a3)
  485.         clr.l    pmPlaneBytes(a3)
  486.         clr.l    pmReserved(a3)
  487.         clr.l    pmBounds(a3)    ; top left = 0
  488.         move.l    #$00200020, pmBounds+4(a3)    ; Dest rect- 0,0,32,32        
  489.  
  490.         ; Do copybits...
  491.         
  492.         move.l        a3, -(sp)                    ; the source pixmap
  493.         move.l        a2 , -(sp) ; DestPM(a6)            ; the dest pixmap
  494.         lea            pmBounds(a3) , a0;
  495.         move.l        a0, -(sp);            ; source rect
  496.         move.l            destRect(a6) , -(sp)
  497.         move.w        #srcOr,-(sp);
  498.         clr.l        -(sp)
  499.         _CopyBits
  500.         
  501.         move.l    a4,a0
  502.         _HUnlock
  503.         move.l    pmTable(a3), -(sp)
  504.         _DisposCTable        
  505.         bra.s okay
  506. Failed:
  507.     _Debugger
  508. Okay:
  509.         movem    (sp)+, d7/a1-a4
  510.         unlk    a6                    ; ditch stack frame
  511.         move.l    (sp)+, a0            ; get return address
  512.         add.l    #iclDrawArgs, sp    ; ditch incoming arguments
  513.         jmp    (a0)                    ; return to caller
  514.  
  515.         ENDWITH
  516.  
  517.         ENDPROC
  518.  
  519.  
  520.         END
  521.